//
//  WPGoldRecordCell.m
//  wobingwoyi
//
//  Created by WGP on 16/9/20.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "WPGoldRecordCell.h"
#import "WPGoldRecordsModel.h"

@interface WPGoldRecordCell ()

@property(nonatomic,strong)UILabel *titleLabel;
@property(nonatomic,strong)UILabel *timeLabel;
@property(nonatomic,strong)UIImageView *iconView;
@property(nonatomic,strong)UILabel *goldCountLabel;

@end
@implementation WPGoldRecordCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setupUI];
    }
    return self;
}

-(void)setupUI
{
    [self titleLabel];
    [self timeLabel];
    [self iconView];
    [self goldCountLabel];
}

-(UILabel *)titleLabel
{
    if (_titleLabel == nil)
    {
        _titleLabel = [UILabel new];
        _titleLabel.font = [UIFont systemFontOfSize:14];
        _titleLabel.textColor = GLobalFontColor;
        [self.contentView addSubview:_titleLabel];
        
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(13);
            make.left.equalTo(self.contentView).offset(15);
        }];
    }
    return _titleLabel;
}

-(UILabel *)timeLabel
{
    if (_timeLabel == nil)
    {
        _timeLabel = [UILabel new];
        _timeLabel.font = [UIFont systemFontOfSize:14];
        _timeLabel.textColor = GloballightFontColor;
        [self.contentView addSubview:_timeLabel];
        
        [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.titleLabel);
            make.top.equalTo(self.titleLabel.mas_bottom).offset(11);
            make.bottom.equalTo(self.contentView).offset(-11);
        }];
    }
    return _timeLabel;
}

-(UILabel *)goldCountLabel
{
    if (_goldCountLabel == nil)
    {
        _goldCountLabel = [UILabel new];
        _goldCountLabel.font = [UIFont systemFontOfSize:20];
        _goldCountLabel.textAlignment = NSTextAlignmentRight;
        [_goldCountLabel sizeToFit];
        
        [self.contentView addSubview:_goldCountLabel];
        
        [_goldCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-10);
            make.centerY.equalTo(self.contentView);
        }];
    }
    return _goldCountLabel;
}

-(UIImageView *)iconView
{
    if (_iconView == nil)
    {
        _iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"jia"]];
        [_iconView sizeToFit];
        
        [self.contentView addSubview:_iconView];
        
        [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.goldCountLabel.mas_left).offset(-10);
            make.centerY.equalTo(self.contentView);
        }];
        
    }
    return _iconView;
}

-(void)setModel:(WPGoldRecordsModel *)model
{
    _model = model;
    self.titleLabel.text = model.title;
    self.timeLabel.text = [[WPDateFormatterManager sharedManager] timeStrWithTimeStampStr:model.tradeTime formatStr:@"yyyy-MM-dd HH:mm"];
    self.goldCountLabel.text = [NSString stringWithFormat:@"%zd",model.amount];
    
    if (model.status)
    {
        self.goldCountLabel.textColor = GlobalColor;
        self.iconView.image = [UIImage imageNamed:@"jia"];
    }
    else
    {
        self.goldCountLabel.textColor = GLobalFontColor;
        self.iconView.image = [UIImage imageNamed:@"jian"];
    }
}

@end
